package com.hsc.www.reSend.core;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BasicProperties;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FreeBasicProperties implements BasicProperties {

    public static final Integer DEFAULT_PRIORITY = 0;

    public static final Integer DEFAULT_DELIVERY_MODE = 1;

    private String contentType;
    private String contentEncoding;
    private Map<String, Object> headers = new HashMap<>();
    private Integer deliveryMode = DEFAULT_DELIVERY_MODE;
    private Integer priority = DEFAULT_PRIORITY;
    private String correlationId;
    private String replyTo;
    private String expiration;
    private String messageId;
    private Date timestamp;
    private String type;
    private String userId;
    private String appId;
    private String clusterId;

    public AMQP.BasicProperties convert2AmqpBasicProperties() {
        return convert2AmqpBasicProperties(this);
    }

    public static AMQP.BasicProperties convert2AmqpBasicProperties(FreeBasicProperties properties) {
        return Objects.isNull(properties) ? null :
                new AMQP.BasicProperties.Builder()
                        .contentEncoding(properties.getContentEncoding())
                        .contentType(properties.getContentType())
                        .headers(properties.getHeaders())
                        .deliveryMode(properties.getDeliveryMode())
                        .priority(properties.getPriority())
                        .correlationId(properties.getCorrelationId())
                        .replyTo(properties.getReplyTo())
                        .expiration(properties.getExpiration())
                        .messageId(properties.getMessageId())
                        .timestamp(properties.getTimestamp())
                        .type(properties.getType())
                        .userId(properties.getUserId())
                        .appId(properties.getAppId())
                        .clusterId(properties.getClusterId())
                        .build();
    }


    public static FreeBasicProperties convert2FreeBasicProperties(AMQP.BasicProperties properties) {
        return Objects.isNull(properties) ? null :
                FreeBasicProperties.builder()
                        .contentEncoding(properties.getContentEncoding())
                        .contentType(properties.getContentType())
                        .headers(properties.getHeaders())
                        .deliveryMode(properties.getDeliveryMode())
                        .priority(properties.getPriority())
                        .correlationId(properties.getCorrelationId())
                        .replyTo(properties.getReplyTo())
                        .expiration(properties.getExpiration())
                        .messageId(properties.getMessageId())
                        .timestamp(properties.getTimestamp())
                        .type(properties.getType())
                        .userId(properties.getUserId())
                        .appId(properties.getAppId())
                        .clusterId(properties.getClusterId())
                        .build();
    }


}
